---
title: "Set Filter - API"
enterprise: true
---

This section describes how the Set Filter can be controlled programmatically using API calls.

## Set Filter Model

Get and set the state of the Set Filter by getting and setting the model on the grid API.

```js
// get filter model
const model = api.getColumnFilterModel('country');

// set filter model and update
await api.setColumnFilterModel('country', { values: ['Spain', 'Ireland', 'South Africa'] });

// refresh rows based on the filter (not automatic to allow for batching multiple filters)
api.onFilterChanged();
```

The filter model contains an array of string values where each item in the array corresponds to an element to be selected from the set.

{% interfaceDocumentation interfaceName="SetFilterModel" /%}

## Set Filter API

The Set Filter consists of two parts - the Set Filter UI (the UI component) and the Set Filter Handler (maintains the values and performs the filter logic).

Note that the Set Filter will always use a filter handler, regardless of whether `enableFilterHandlers` is enabled (which controls filter handlers for [Custom Filter Components](./component-filter/)).

The Set Filter values can be updated via the Set Filter Handler:

```{% frameworkTransform=true %}
// get filter handler
const countryFilterHandler = api.getColumnFilterHandler('country');
```

The `SetFilterHandler` interface defines the public API for the Set Filter Handler.

{% interfaceDocumentation interfaceName="SetFilterHandler" /%}

The Mini Filter can be interacted with via the Set Filter UI instance:

```{% frameworkTransform=true %}
// get filter UI instance
api.getColumnFilterInstance('country').then(countryFilterComponent => {
    // use set filter UI instance
});
```

The `SetFilterUi` interface defines the public API for the Set Filter UI component.

{% interfaceDocumentation interfaceName="SetFilterUi"  /%}

In the example below, you can see how the filter for the Athlete column is modified through the API.

{% gridExampleRunner title="Set Filter API" name="set-filter-api"  exampleHeight=570 /%}

### Enabling Case-Sensitivity

By default the API is case-insensitive. You can enable case sensitivity by using the `caseSensitive: true` filter parameter:

```{% frameworkTransform=true %}
const gridOptions = {
    columnDefs: [
        {
            field: 'colour',
            filter: 'agSetColumnFilter',
            filterParams: {
                caseSensitive: true
            }
        }
    ]
}
```

{% note %}
The `caseSensitive` option also affects [Mini-Filter](./filter-set-mini-filter/#enabling-case-sensitive-searches) searches and the values presented in the [Filter List](./filter-set-filter-list/#enabling-value-case-sensitivity).
{% /note %}

The following example demonstrates the difference in behaviour between `caseSensitive: false` (the default) and `caseSensitive: true`:

* With `caseSensitive: false` (the default):
  * `setModel()` will perform **case-insensitive** matching against available values to decide what is enabled in the Filter List.
  * `setFilterValues()` will override the available values and force the case of the presented values in the Filter List to those provided.
    * Selected values will be maintained based upon **case-insensitive** matching.
* With `caseSensitive: true`:
  * `setModel()` will perform **case-sensitive** matching against available values to decide what is enabled in the Filter List.
  * `setFilterValues()` will override the available values and force the case of the presented values in the Filter List to those provided.
    * Selected values will be maintained based upon **case-sensitive** matching.
* In both cases `getModel()` and `getFilterValues()` will return the values with casing that matches those displayed in the Filter List. This is printed to the developer console.

{% gridExampleRunner title="Set Filter API - Case Sensitivity" name="set-filter-api-case-sensitive"  exampleHeight=570 /%}

## Next Up

Continue to the next section to learn about [Multi Filters](./filter-multi/).
